/* fafamtp.p FIXED ASSET MAINTENANCE - DEPRECIATION SCHEDULE            */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: fafamtp.p 17054 2012-04-26 05:48:07Z as8                          $: */
/* $Revision: 1.14.1.10 $                                                         */
/*V8:ConvertMode=NoConvert                                              */
/* REVISION: 9.1     LAST MODIFIED: 10/26/99     BY: *N021* Pat Pigatti */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 07/28/00   BY: *N0BX* Arul Victoria    */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0L0* Jacolyn Neder    */
/* Revision: 1.14.1.9  BY: Paul Donnelly (SB) DATE: 06/26/03 ECO: *Q00C* */
/* $Revision: 1.14.1.10 $    BY: Vandna Rohira         DATE: 12/17/04  ECO: *P2Z5*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*-Revision end---------------------------------------------------------------*/

{us/bbi/mfdeclre.i}
{us/bbi/gplabel.i} /* EXTERNAL LABEL INCLUDE */
{us/gp/gprunpdf.i "mcpl" "p"}

/* --------------------  Define Query  ------------------- */
define query q_fabd_det for
   fabd_det scrolling. /* Leave out fields list as it conflicts
with Oracle */

/* -----------------  Standard Variables  ---------------- */
define variable p-status as character no-undo.
define variable perform-status as character format "x(25)"
   initial "first" no-undo.
define variable p-skip-update like mfc_logical no-undo.
define variable l-rowid as rowid no-undo.
define variable l-delete-it like mfc_logical no-undo.
define variable l-del-rowid as rowid no-undo.
define variable l-top-rowid as rowid no-undo.
define variable lines as integer initial 10 no-undo.
define variable l-found like mfc_logical no-undo.
define variable pos as integer no-undo.
define variable l-first like mfc_logical no-undo.
define variable l-error like mfc_logical no-undo.
define variable l-title as character no-undo.
define variable l_amt_fmt         as character      no-undo.
define variable mc-error-number   like msg_nbr      no-undo.
define variable rndmthd           like rnd_rnd_mthd no-undo.


/* ------------------  Button Variables  ----------------- */
define button b-end label "End".

/* -------------  Standard Widget Variables  ------------- */
define variable l-focus as widget-handle no-undo.
define variable w-frame as widget-handle no-undo.

/* ------------------  Screen Variables  ----------------- */
define shared variable l-fa-id as character format "x(12)" no-undo.
define shared variable l-fabk-id as character format "x(4)" no-undo.
define variable l-resrv-desc as character format "x(12)" no-undo.
define variable l-yrper as character format "x(7)" no-undo.

/* ------------------  Frame Definition  ----------------- */
/* Added side-labels phrase to frame statement              */

define frame f-button
   b-end at 1
with no-box overlay three-d side-labels width 10.

/* CLEAR FRAME REGISTRATION TO TRANSLATE THE FRAME EVERYTIME*/
clearFrameRegistration(frame f-button:handle).

/* SET EXTERNAL LABELS */
setFrameLabels(frame f-button:handle).

assign
   l-focus = b-end:handle in frame f-button
   b-end:width = 8
   b-end:private-data = "end".

define frame f-1
   skip(.4)
   space(1)
   l-yrper column-label "Period"
   fabd_resrv
   format ">>>9"
   l-resrv-desc column-label "Type"
   fabd_faloc_id
   fabd_peramt
with three-d overlay 8 down scroll 1 width 80.

/* CLEAR FRAME REGISTRATION TO TRANSLATE THE FRAME EVERYTIME*/
clearFrameRegistration(frame f-1:handle).

/* SET EXTERNAL LABELS */
setFrameLabels(frame f-1:handle).

run ip-framesetup.

assign
   w-frame = frame f-1:handle.
{us/bbi/gprun.i ""fafmtut.p""
   "(w-frame)"}

assign
   lines = 8.

open query q_fabd_det for each fabd_det
   where fabd_det.fabd_domain = global_domain and  fabd_fa_id =
   l-fa-id and
   fabd_fabk_id = l-fabk-id
   use-index fabd_fa_id no-lock.

get first q_fabd_det no-lock.

l_amt_fmt = fabd_peramt:format in frame f-1.

main-loop:
do while perform-status <> "end" on error undo:
   run ip-query
      (input-output perform-status,
      input-output l-rowid).

   /* ----------------------  Display  ---------------------- */
   run ip-predisplay.

   /* -----------------------  end  ----------------------- */
   if perform-status = "end"
   then do:
      hide frame f-1 no-pause.
      delete PROCEDURE this-procedure no-error.
      leave.
   end.  /* IF perform-status = "end"  */
   /* ----------------  Selection Buttons  ---------------- */
   if perform-status <> "first"
   then
      run ip-button
         (input-output perform-status).
end.  /* MAIN-LOOP */

PROCEDURE ip-predisplay:
   if (perform-status = "" or
      perform-status = "update") and
      available fabd_det
   then
      display-loop:
      do:
         if perform-status = ""
         then do:
            clear frame f-1 all no-pause.
            l-top-rowid = rowid(fabd_det).
         end.  /* IF perform-status = ""  */
         read-loop:
         do pos = 1 to lines:
            if perform-status = ""
            then do:
               if session:display-type = "gui"
               then
                  assign
                     l-yrper:bgcolor = 8
                     l-yrper:fgcolor = 0.
               else
                  color display normal l-yrper
                  with frame f-1.
            end.  /* IF perform-status = ""  */
            run ip-displayedits.
            if perform-status = "update"
            then
               leave display-loop.
            if pos < lines
            then
               down with frame f-1.
            get next q_fabd_det no-lock.
            if not available fabd_det
            then
               leave.
         end.  /* READ-LOOP */
         run ip-postdisplay.
      end.  /* DISPLAY-LOOP */
END PROCEDURE. /* ip-predisplay */

PROCEDURE ip-displayedits:
   if available fabd_det
   then do:

      /* DISPLAY-EDITS */
      l-resrv-desc = "".
      if fabd_resrv = 0
      then do:
         {us/gp/gplngn2a.i
            &file = ""audit""
            &field = ""desc""
            &code = ""1""
            &mnemonic = l-resrv-desc
            &label = l-resrv-desc}
      end.  /* IF fabd_resrv = 0   */
      else do:
         {us/gp/gplngn2a.i
            &file = ""faadj_mstr""
            &field = ""faadj_type""
            &code = fabd_resrv_type
            &mnemonic = l-resrv-desc
            &label = l-resrv-desc}
      end.  /* IF NOT fabd_resrv = 0   */
      assign
         l-yrper = if available fabd_det
                   then
                      substring(fabd_yrper,1,4) + "-" +
                      substring(fabd_yrper,5,6)
                   else
                      "".
      /* DISPLAY-EDITS */

      {us/gp/gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
                "(input base_curr,
                  output rndmthd,
                  output mc-error-number)"}
      if mc-error-number <> 0 then do:
         {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
      end.

      {us/bbi/gprun.i ""gpcurfmt.p""
                "(input-output l_amt_fmt, input rndmthd)"}

      assign fabd_det.fabd_peramt:format in frame f-1 = l_amt_fmt.

      run ip-display.
   end.  /* IF AVAILABLE fabd_det  */
END PROCEDURE. /* ip-displayedits */

PROCEDURE ip-display:
   display
      fabd_det.fabd_peramt
      fabd_det.fabd_faloc_id
      l-resrv-desc
      fabd_det.fabd_resrv
      l-yrper
   with frame f-1.
END PROCEDURE. /* ip-display */

PROCEDURE ip-postdisplay:
   do pos = 1 to lines:
      if frame-line(f-1) <= 1
      then
         leave.
      up 1 with frame f-1.
   end.  /* DO pos = 1 TO LINES */
   if perform-status = ""
   then do:
      reposition q_fabd_det to rowid l-top-rowid no-error.
      get next q_fabd_det no-lock.
      assign
         l-rowid = l-top-rowid.
      color display message l-yrper
      with frame f-1.
   end.  /* IF perform-status = ""  */
END PROCEDURE. /* ip-postdisplay */

PROCEDURE ip-query:
   define input-output parameter perform-status as character
      no-undo.
   define input-output parameter l-rowid as rowid no-undo.

   if perform-status = "first"
   then do:
      if l-rowid <> ?
      then do:
         reposition q_fabd_det to rowid l-rowid no-error.
         get next q_fabd_det no-lock.
      end.  /* IF l-rowid <> ?  */
      if not available fabd_det
      then
         get first q_fabd_det no-lock.
      if available fabd_det
      then
         assign
            perform-status = ""
            l-rowid = rowid(fabd_det).
      else do:
         assign
            perform-status = ""
            l-rowid = ?.
         assign
            frame f-1:visible = true.
         return.
      end.  /* IF NOT AVAILABLE fabd_det  */
   end.  /* IF perform-status = "first"  */
   if perform-status = "open"
   then do:
      open query q_fabd_det for each fabd_det
         where fabd_det.fabd_domain = global_domain and  fabd_fa_id =
         l-fa-id and
         fabd_fabk_id = l-fabk-id
         use-index fabd_fa_id no-lock.

      reposition q_fabd_det to rowid l-rowid no-error.
      get next q_fabd_det no-lock.
      if available fabd_det
      then
         assign
            perform-status = ""
            l-rowid = rowid(fabd_det).
      else do:
         get first q_fabd_det no-lock.
         if not available fabd_det
         then do:
            assign
               perform-status = ""
               frame f-1:visible = true.
            return.
         end.  /* IF NOT AVAILABLE fabd_det  */
         else
            assign
               perform-status = ""
               l-rowid = rowid(fabd_det).
      end.  /* IF NOT AVAILABLE fabd_det  */
   end.  /* IF perform-status = "open"  */
   if perform-status = "next"
   then do:
      get next q_fabd_det no-lock.
      if available fabd_det
      then do:
         hide message no-pause.
         assign
            l-rowid = rowid(fabd_det)
            perform-status = "next".
         if session:display-type = "gui"
         then
            assign
               l-yrper:bgcolor = 8
               l-yrper:fgcolor = 0.
         else
            color display normal l-yrper
            with frame f-1.
         pause 0.  /* MAKES SCROLLING WORK - DON'T REMOVE */
         down 1 with frame f-1.
         run ip-displayedits.
         color display message l-yrper
         with frame f-1.
      end.  /* IF AVAILABLE fabd_det  */
      else do:
         assign
            perform-status = "next".
         {us/bbi/pxmsg.i &MSGNUM=20 &ERRORLEVEL=2} /* END OF FILE */
         get last q_fabd_det no-lock.
      end.  /* IF NOT AVAILABLE fabd_det  */
   end.  /* IF perform-status = "next"  */
   if perform-status = "prev"
   then do:
      get prev q_fabd_det no-lock.
      if not available fabd_det
      then do:
         {us/bbi/pxmsg.i &MSGNUM=21 &ERRORLEVEL=2} /* BEGINNING OF FILE */
         get first q_fabd_det no-lock.
         return.
      end.  /* IF NOT AVAILABLE fabd_det  */
      hide message no-pause.
      l-rowid = rowid(fabd_det).
      if session:display-type = "gui"
      then
         assign
            l-yrper:bgcolor = 8
            l-yrper:fgcolor = 0.
      else
         color display normal l-yrper
         with frame f-1.
      pause 0.  /* MAKES SCROLLING WORK - DON'T REMOVE */
      up 1 with frame f-1.
      run ip-displayedits.
      color display message l-yrper
      with frame f-1.
   end.  /* IF perform-status = "prev"  */
   if perform-status = "update" or
      perform-status = "delete"
   then do:
      get current q_fabd_det no-lock.
      if not available fabd_det
      then do:
         hide message no-pause.
         {us/bbi/pxmsg.i &MSGNUM=1310 &ERRORLEVEL=3} /* RECORD NOT FOUND */
         assign
            perform-status = "".
      end.  /* IF NOT AVAILABLE fabd_det  */
   end.  /* IF perform-status = "update" OR ... */
END PROCEDURE. /* ip-query */

PROCEDURE ip-framesetup:
   if session:display-type = "gui"
   then
      assign
         frame f-1:row = 4.5.
   else
      assign
         frame f-1:row = 4.

   assign
      frame f-1:box = true
      frame f-1:centered = true
      frame f-1:title = (getFrameTitle("DEPRECIATION_SCHEDULE",30))
      frame f-button:centered = true
      frame f-button:row = 20.
END PROCEDURE. /* ip-framesetup */

PROCEDURE ip-button:
   define input-output parameter perform-status as character
      format "x(25)" no-undo.
   enable all with frame f-button.
   assign
      ststatus = stline[1].
   status input ststatus.

   on choose of b-end
   do:
      assign
         perform-status = self:private-data
         l-focus = self:handle.
      hide frame f-1 no-pause.
      hide frame f-button no-pause.
   end.  /* ON CHOOSE OF b-end */

   on cursor-up, f9 anywhere
   do:
      assign
         perform-status = "prev"
         l-focus = focus:handle.
      apply "go" to frame f-button.
   end.  /* ON CURSOR-UP, F9 ANYWHERE */

   on cursor-down, f10 anywhere
   do:
      assign
         perform-status = "next"
         l-focus = focus:handle.
      apply "go" to frame f-button.
   end.  /* ON CURSOR-DOWN, F10 ANYWHERE */

   on cursor-right anywhere
   do:
      assign
         l-focus = self:handle.
      apply "tab" to l-focus.
   end.  /* ON CURSOR-RIGHT ANYWHERE */

   on cursor-left anywhere
   do:
      assign
         l-focus = self:handle.
      if session:display-type = "gui"
      then
         apply "shift-tab" to l-focus.
      else
         apply "ctrl-u" to l-focus.
   end.  /* ON CURSOR-LEFT ANYWHERE */

   on esc anywhere
   do:
      if session:display-type = "gui"
      then
         apply "choose" to b-end in frame f-button.
   end.  /* ON ESC ANYWHERE */

   on end-error anywhere
      apply "choose" to b-end in frame f-button.

   on window-close of current-window
      apply "choose" to b-end in frame f-button.

   on go anywhere
   do:
      if (lastkey = keycode("cursor-down") or
         lastkey = keycode("cursor-up") or
         lastkey = keycode("f9") or
         lastkey = keycode("f10"))
      then
         return.
      else
      assign
         l-focus = focus:handle.
      apply "choose" to l-focus.
   end.  /* ON GO ANYWHERE */

   wait-for
      go of frame f-button or
      window-close of current-window or
      choose of
      b-end
      focus
      l-focus.
   hide message no-pause.
END PROCEDURE. /* ip-button */
